/***********************************************
 This file is part of redia-bapps-main-ios.
 
 Copyright (c) 2015 Redia A/S
 
 Redia-bapps-main-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 redia-bapps-main-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-bapps-main-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

//
//  BAUtils.h
//  redia-bapps-ios
//
//  Created by Henrik Lynbech on 09/08/13.
//  Copyright (c) 2013 redia. All rights reserved.
//

#import <Foundation/Foundation.h>

#define BA_FONT_REGULAR(fontsize) [UIFont fontWithName:@"Roboto-Regular" size:fontsize]
#define BA_FONT_LIGHT(fontsize) [UIFont fontWithName:@"Roboto-Light" size:fontsize]
#define BA_FONT_BOLD(fontsize) [UIFont fontWithName:@"Roboto-Bold" size:fontsize]
#define BA_FONT_MEDIUM(fontsize) [UIFont fontWithName:@"Roboto-Medium" size:fontsize]
#define BA_FONT_THIN(fontsize) [UIFont fontWithName:@"Roboto-Thin" size:fontsize]

#define BA_LABEL_SET_FONT_REGULAR(label) label.font = [UIFont fontWithName:@"Roboto-Regular" size:label.font.pointSize];
#define BA_LABEL_SET_FONT_LIGHT(label) label.font = [UIFont fontWithName:@"Roboto-Light" size:label.font.pointSize];
#define BA_LABEL_SET_FONT_BOLD(label) label.font = [UIFont fontWithName:@"Roboto-Bold" size:label.font.pointSize];
#define BA_LABEL_SET_FONT_MEDIUM(label) label.font = [UIFont fontWithName:@"Roboto-Medium" size:label.font.pointSize];
#define BA_LABEL_SET_FONT_THIN(label) label.font = [UIFont fontWithName:@"Roboto-Thin" size:label.font.pointSize];

#define BA_LABEL_SET_FONT_REGULAR_WITH_SIZE(label, fontsize) label.font = [UIFont fontWithName:@"Roboto-Regular" size:fontsize];
#define BA_LABEL_SET_FONT_LIGHT_WITH_SIZE(label, fontsize) label.font = [UIFont fontWithName:@"Roboto-Light" size:fontsize];
#define BA_LABEL_SET_FONT_BOLD_WITH_SIZE(label, fontsize) label.font = [UIFont fontWithName:@"Roboto-Bold" size:fontsize];
#define BA_LABEL_SET_FONT_MEDIUM_WITH_SIZE(label, fontsize) label.font = [UIFont fontWithName:@"Roboto-Medium" size:fontsize];
#define BA_LABEL_SET_FONT_THIN_WITH_SIZE(label, fontsize) label.font = [UIFont fontWithName:@"Roboto-Thin" size:fontsize];


#define BA_BUTTON_ADD_PRESSED_STATE_OVERLAY(button) \
    { \
        UIView *__overlay_view = [[UIView alloc] initWithFrame:button.bounds]; \
        __overlay_view.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.2]; \
        UIGraphicsBeginImageContext(button.bounds.size); \
        [__overlay_view.layer renderInContext:UIGraphicsGetCurrentContext()]; \
        [button setBackgroundImage:UIGraphicsGetImageFromCurrentImageContext() forState:UIControlStateHighlighted]; \
        UIGraphicsEndImageContext(); \
    }

#define BA_BUTTON_ADD_LIGHT_PRESSED_STATE_OVERLAY(button) \
{ \
UIView *__overlay_view = [[UIView alloc] initWithFrame:button.bounds]; \
__overlay_view.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.2]; \
UIGraphicsBeginImageContext(button.bounds.size); \
[__overlay_view.layer renderInContext:UIGraphicsGetCurrentContext()]; \
[button setBackgroundImage:UIGraphicsGetImageFromCurrentImageContext() forState:UIControlStateHighlighted]; \
UIGraphicsEndImageContext(); \
}

#define BA_FLYOUT_MENU_ADD_BUTTON(mode) \
    { \
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; \
        if (mode == BASpecialNavigationBarConfigurationCompletelyColored) { \
            [button setImage:[BAUtils instance].whiteTopRightMenu forState:UIControlStateNormal]; \
        } \
        else { \
            [button setImage:[BAUtils instance].grayTopRightMenu forState:UIControlStateNormal]; \
        } \
        [button addTarget:self action:@selector(flyoutMenuClicked) forControlEvents:UIControlEventTouchUpInside]; \
        [button setFrame:CGRectMake(0, 0, 32, 32)]; \
        if ([[BAUtils instance] iOSMajorVersion] > 6) { \
            UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; \
            item.width = -6; \
            [self.navigationItem setRightBarButtonItems:@[item, [[UIBarButtonItem alloc] initWithCustomView:button]]]; \
        } \
        else { \
            UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; \
            item.width = 5; \
            [self.navigationItem setRightBarButtonItems:@[item, [[UIBarButtonItem alloc] initWithCustomView:button]]]; \
        } \
    }

#define BA_FLYOUT_MENU_ADD_CALLBACK \
- (void)flyoutMenuClicked \
{ \
    if (self.slideNavigationViewController.currentSlideDirection == MWFSlideDirectionNone) { \
        [self.slideNavigationViewController slideWithDirection:MWFSlideDirectionLeft]; \
    } \
    else { \
        [self.slideNavigationViewController slideWithDirection:MWFSlideDirectionNone]; \
    } \
}




@interface BAUtils : NSObject

SINGLETON_DECL_GCD(BAUtils)

@property (nonatomic, strong) UIImage* grayBackButtonImage;
@property (nonatomic, strong) UIImage* whiteBackButtonImage;
@property (nonatomic, strong) UIImage* grayTopRightMenu;
@property (nonatomic, strong) UIImage* whiteTopRightMenu;
@property (assign, nonatomic) NSInteger iOSMajorVersion;

@property (nonatomic, strong) UIImage* iPadWhiteTopLeftClose;
@property (nonatomic, strong) UIImage* iPadGrayTopLeftClose;

+(NSString*)makeCommaSeparatedStringFromStrings:(NSArray*)stringArray;

/*
 getLibrariesAsyncFromView is deprecated, needs new impl
+(void)hardWireToCustomerId:(NSString*)customerId resultBlock:(void(^)())resultBlock;
 */

/**
 This method automatically adds layoutconstraints to a views superview. Ideal when adding a viewcontrollers view to a containerview!
 
 @param view the view that needt to fill it's superview
 @discussion This method can in some cases crash if auto layout is not supported by the views superview. Use with caution!
 */
+(void)setViewToFillParent:(UIView*)view;

@end
